<?php
namespace Admin\Controller;
use Think\Controller;
class InformationController extends Controller {

	//俱乐部简介信息列表
	public function clubintroduce(){

        $clubintr=M('clubintr');
        $list = $clubintr->select();
        //var_dump($list);
        $this->assign('data',$list);// 赋值数据集
     	$this->display();
    }

	//俱乐部课程信息列表
    public function clubcourse(){
    	$clubcourse=M('clubcourse');
        $list = $clubcourse->select();
        //var_dump($list);
        $this->assign('data',$list);// 赋值数据集
        $this->display();
    }

    //俱乐部样例视频列表
    public function clubvideo(){
    	$clubvideo=M('examplevideo');
        $list = $clubvideo->select();
        //var_dump($list);
        foreach($list as $key=>$value)
        { 
            foreach($value as $key2=>$value2)
            { 
                if($key2=='clubintr_id'){
                    

                    $listg[$key]['video_id'] = $list[$key]['video_id'];
                    $listg[$key]['video_refer'] = $list[$key]['video_refer'];
                    $listg[$key]['browser_times'] = $list[$key]['browser_times'];
                    $listg[$key]['recent_update'] = $list[$key]['recent_update'];

                    $clubintr=M('clubintr');
                    $cid = $list[$key]['clubintr_id'];
                    $list3 = $clubintr->where("clubintr_id=$cid")->select();
                    $listg[$key]['club_name'] = $list3['0']['club_name'];
                    $this->assign('data',$listg);// 赋值数据集

                }
            }
        }

        $this->display();
    }

    //俱乐部简介信息修改页面(用于初始化表单)
    public function clubedit(){
       
        $id=$_GET['id'];
        $intr=M('clubintr');
        $list = $intr->where("clubintr_id = $id ")->select();
        $this->assign('data',$list);//用于初始化表单
        $this->display();
    }

    //修改俱乐部简介信息
    public function doclubedit(){

        //获取表单数据,通过标签中的name属性。
    	$clubintr_id = I('post.clubid');//获取俱乐部ID（这步很重要哦）
        $clubname = I('post.clubname');
        $clubintr = I('post.clubintr');
        $place = I('post.place');
        $phone = I('post.phone');
        $joindate = I('post.joindate');
        $clubpic = I('post.clubpic');
        $opendate = I('post.opendate');

        //保存数据到data数组
        $data['club_name'] = $clubname;
        $data['club_intr'] =  $clubintr;
        $data['club_place'] = $place;
        $data['club_phone'] = $phone ;
        $data['join_time'] = $joindate;
        $data['club_pic'] = $clubpic;
        $data['open_time'] = $opendate;
    	
    	$clubintr=M('clubintr');
        $result = $clubintr->where("clubintr_id = $clubintr_id ")->save($data);
        if($result==FALSE){
            $this->error("修改失败！");
        }else{
            $this->success("修改成功！");
        }
    }

    //删除俱乐部简介信息
    public function clubdelete(){

        $clubintr_id=$_GET['id'];
        //var_dump($clubintr_id);
    	$clubintr=M('clubintr');

        if($clubintr->where("clubintr_id=$clubintr_id")->delete())
        {
            $this->success('删除成功',U('Information/clubintroduce'));
        }
        else{

            $this->error('删除失败');
        }
    }

    //俱乐部课程内容修改页面(初始化表单)
    public function courseedit(){
       
        $id=$_GET['id'];
        $intr=M('clubcourse');
        $list = $intr->where("course_id = $id ")->select();
        $this->assign('data',$list);//用于初始化表单
        $this->display();
    }

    //修改俱乐部课程内容
    public function docourseedit(){

        $course_id = I('post.courseid');//获取俱乐部课程ID（这步很重要哦）
        $coursename = I('post.coursename');
        $courseintr = I('post.courseintr');
        $courseprice = I('post.courseprice');
        $coursepeople = I('post.coursepeople');
        $createtime = I('post.createtime');
      

        //保存数据到data数组
        $data['course_id'] = $course_id;
        $data['course_name'] =  $coursename;
        $data['course_intr'] = $courseintr;
        $data['course_price'] = $courseprice ;
        $data['course_people'] = $coursepeople;
        $data['create_time'] = $createtime;
        
        $clubcourse=M('clubcourse');
        $result = $clubcourse->where("course_id = $course_id ")->save($data);
        if($result==FALSE){
            $this->error("修改失败！");
        }else{
            $this->success("修改成功！");
        }
        
    }

    //删除俱乐部课程信息
    public function coursedelete(){
       
        $course_id=$_GET['id'];
        //var_dump($clubintr_id);
        $clubcourse=M('clubcourse');

        if($clubcourse->where("course_id=$course_id")->delete())
        {
            $this->success('删除成功',U('Information/clubcourse'));
        }
        else{

            $this->error('删除失败');
        }
    }

     //俱乐部课程信息(用于显示添加页面)
    public function courseadd(){
       
        $this->display();
    }

    //添加俱乐部课程信息
    public function docourseadd(){
       
        $clubintr_id = I('post.clubintrid');
        $coursename = I('post.coursename');
        $courseintr = I('post.courseintr');
        $courseprice = I('post.courseprice');
        $coursepeople = I('post.coursepeople');
        $createtime = I('post.createtime');
      

        //保存数据到data数组
        $data['clubintr_id'] = $clubintr_id;
        $data['course_name'] =  $coursename;
        $data['course_intr'] = $courseintr;
        $data['course_price'] = $courseprice ;
        $data['course_people'] = $coursepeople;
        $data['create_time'] = $createtime;
        
        $clubcourse=M('clubcourse');
        $result = $clubcourse->add($data);
        if($result==FALSE){
            $this->error("添加失败！");
        }else{
            $this->success("添加成功！");
        }
    }

    //显示样例视频页面
    public function videoadd(){
       
        $this->display();
    }

    //添加样例视频
    public function dovideoadd(){
       
        $clubintr_id = I('post.clubintrid');
        $videorefer = I('post.videorefer');
        $browsertimes = I('post.browsertimes');
        $recentupdate = I('post.recentupdate');
    
        //保存数据到data数组
        $data['clubintr_id'] = $clubintr_id;
        $data['video_refer'] =  $videorefer;
        $data['browser_times'] = $browsertimes;
        $data['recent_update'] = $recentupdate ;
       
        
        $examplevideo=M('examplevideo');
        $result = $examplevideo->add($data);
        if($result==FALSE){
            $this->error("添加失败！");
        }else{
            $this->success("添加成功！");
        }
    }

     //显示样例视频编辑页面
    public function examplevedit(){

        $id=$_GET['id'];
        $intr=M('examplevideo');
        $list = $intr->where("video_id = $id ")->select();
        $this->assign('data',$list);//用于初始化表单
        $this->display();
       
    }

     //编辑样例视频
    public function doexamplevedit(){

        $video_id = I('post.videoid');
        $videorefer = I('post.videorefer');
        $browsertimes = I('post.browsertimes');
        $recentupdate = I('post.recentupdate');
      
        //保存数据到data数组
        $data['video_id'] = $video_id;
        $data['video_refer'] =  $videorefer;
        $data['browser_times'] = $browsertimes;
        $data['recent_update'] = $recentupdate ;

        $examplevideo=M('examplevideo');
        $result = $examplevideo->where("video_id = $video_id ")->save($data);
        if($result==FALSE){
            $this->error("修改失败！");
        }else{
            $this->success("修改成功！");
        }
       
    }

    //搜索视频
    public function searchcourse(){

        $key = $_GET['key'];
        $coursenum = M('clubcourse')->where('course_name like "%'.$key.'%"')->count();
        $Page = new \Think\Page($coursenum,2);
        $this->coursenum=$coursenum;
        $this->coursepage=$Page->show();
        $this->courselist=M('clubcourse')
            ->where('course_name like "%'.$key.'%"')
            ->order('course_id')
            ->limit($Page->firstRow,2)
            ->select();

        $this->display();
    }
    
}

